<template>
	<view class="content">
		<view v-if="list.length > 0" class="list-wrap">
			<view class="list-item" v-for="item in list" :key="item.id">
				<view class="list-info">
					<text class="info">开播时长：</text>
					<text class="duration">{{item.value | getDuration}}</text>
				</view>
				<view class="time">
					<text>{{item.created_at}}</text>
				</view>
			</view>
		</view>
		<view v-if="empty" class="empty-wrap">
			<image class="empty-icon" src="../../static/img/empty.png" mode=""></image>
			<text class="empty-text">暂无数据~</text>
		</view>
		<uni-load-more :status="status" :content-text="contentText"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	export default {
		data() {
			return {
				myInfo: {},
				empty: false,
				list: [],
				page: 1,
				status: 'more',
				contentText: {
					contentdown: '加载更多',
					contentrefresh: '加载中',
					contentnomore: '木有了~'
				},
			}
		},
		onLoad(options) {
			try {
				const myInfo = uni.getStorageSync('myInfo');
				if (myInfo) {
					this.myInfo = myInfo
				}
			} catch (e) {
				console.log(e)
			}
		},
		onUnload() {
			
		},
		onReady() {
			this.getLiveHisory();
		},
		onPullDownRefresh() {
			this.page = 1;
			setTimeout(() => {
				this.getLiveHisory();
			}, 500)
		},
		onReachBottom() {
			this.status = 'loading';
			this.getLiveHisory();
		},
		methods: {
			getLiveHisory: function () {
				this.$api.api.ajaxData({
					method: 'V2.LiveHisory',
					uid: this.myInfo.id,
					token: this.myInfo.token,
					page: this.page
				}, res => {
					uni.stopPullDownRefresh();
					if (res.status) {
						if (this.page == 1) {
							this.list = res.data.list
							this.page++
							this.status = 'more'
							if (this.list.length == 0) {
								this.empty = true
							} else {
								this.empty = false
							}
						} else {
							if (res.data.list.length > 0) {
								for (let i = 0; i < res.data.list.length; i++) {
									this.list.push(res.data.list[i])
								}
								this.page++
								this.status = 'more'
							} else {
								this.status = 'noMore'
							}
						}
					}
				})
			},
			
		},
		filters: {
			getDuration(value) {
				let _s = parseInt(value);
				let s = _s%60;
				let h = 0;
				let m = parseInt(_s/60)
				if (m > 60) {
					h = parseInt(m/60)
					m = m%60
				}
				return (h > 0 ? (h+'小时') : '') + (m > 0 ? (m+'分钟') : '') + (s > 0 ? (s+'秒') : '')
			}
		}
	}
</script>

<style lang="scss">
	@import '../../common/common.scss';
	.list-item {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding: 20rpx;
		background-color: #fff;
		margin-bottom: 10rpx;
		.list-info {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			flex: 1;
			.info {
				font-size: 28rpx;
				color: $text-color;
			}
			.duration {
				font-size: 32rpx;
				color: $main-color;
			}
		}
		.time {
			text {
				font-size: 28rpx;
				color: $text-color;
			}
		}
	}
</style>
